package Test;

import vo.Student;
import vo.Track;

import javax.print.DocFlavor;
import javax.swing.*;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toSet;

public class Test1 {

    private static String[] words = new String[]{"hello", "word"};


    public static void test1() {
        List<String> collect = Stream.of("1", "2", "3")
                .filter(e -> e.equals("1")).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }

    public static void test2() {
        Set<String> collect = Stream.of("a", "b", "c")
                .map(e -> e.toUpperCase()).collect(Collectors.toSet());
        collect.forEach(System.out::println);
    }

    public static void test3() {
        List<String[]> collect = Stream.of(words).
                map(e -> e.split("")).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }

    public static void test4() {
        List<String> collect = Arrays.stream(words).
                flatMap(e -> Stream.of(e.split(""))).collect(Collectors.toList());
        collect.forEach(System.out::println);
    }

    public static void test5() {
        List<String> collect = Stream.of(words).map(e -> e.split(""))
                .flatMap(s -> Arrays.stream(s)).collect(Collectors.toList());
    }

    public static void test6() {
        List<Integer> collect = Stream.of(Arrays.asList(1, 2), Arrays.asList(3, 4))
                .flatMap(e -> e.stream())
                .collect(Collectors.toList());
        collect.forEach(System.out::println);
    }

    public static void test7() {
        List<Track> tracks = Arrays.asList(new Track("1", 24),
                new Track("3", 11),
                new Track("4", 44));

        Track track = tracks.stream().max(Comparator.comparing(e -> e.getLength())).get();
        System.out.println(track.getName());

    }

    public static void test8(){
        List<Track> tracks = Arrays.asList(new Track("1", 24),
                new Track("3", 11),
                new Track("4", 44));

        Track track = tracks.get(0);
        for (Track track1 : tracks) {
            if (track1.getLength()<track.getLength()){
                track=track1;
            }
        }
        System.out.println(track.getName());
    }




    public static void main(String[] args) {
        test3();
    }

}
